package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderStatisticsVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {

    /*
     * 添加订单数据
     * */
    void insert(Orders orders);

    /*
     * 条件查询订单数据
     * */
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /*
     * 根据主键查订单
     * */
    @Select("select * from orders where id=#{id}")
    Orders selectById(Long id);

    @Delete("delete from orders where id=#{id}")
    void deleteById(Long id);

    /*
     *修改订单
     * */
    void update(Orders orders);


    /*
     * 根据状态查询
     * */
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);

    /*
     * 查询超时订单
     * */
    @Select("select * from orders where status=#{status} and order_time<#{orderTime}")
    List<Orders> getByStatusandOrderTimeLT(Integer status, LocalDateTime orderTime);

    /*
     *根据动态条件查询营业额
     * */
    Double getSumByMap(Map map);

    /*
     * 动态查询订单数
     * */
    Integer countByMap(Map map);

    /*
    动态查询销量前10
    * */
    List<GoodsSalesDTO> getSalesTop(LocalDateTime begin, LocalDateTime end);
}
